home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: TRRectObj.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1992-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* See the files "=How to write your app" and "=Using TreeObj.c" for information
- ** on this function. */
-
- /* This file implements the messages for the round-rect object. Many of the messages
- ** can be handled by the rect object, as they deal with a rect structure. Only
- ** a few of them are round-rect-specific. */
-
- /* It would seem that you would want a custom hit-test message handler here, but
- ** the rect object first checks to see if the hit is within the bounding box of
- ** the object, and if so, it then calls the object to return the region. This
- ** allows the rect object to generically handle hit-testing. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- #pragma segment DrawObjects
- long TRRectObj(TreeObjHndl hndl, short message, long data)
- {
- Rect rct, grabber, *rptr;
- RgnHandle rgn, accumRgn;
- short w, h, oldh, oldw;
- ClickInfo *click;
- TreeObjHndl hhndl;
- Point where, pt, curMouse;
- EventRecord option;
- RGBColor rgb, rgb2;
- #if VH_VERSION
- char *cptr;
- #endif
-
- switch (message) {
- case INITMESSAGE:
- TRectObj(hndl, message, data);
- mDerefRRect(hndl)->width = mDerefRRect(hndl)->height = 20;
- break;
-
- case FREEMESSAGE:
- case COPYMESSAGE:
- case UNDOMESSAGE:
- case CONVERTMESSAGE:
- case FREADMESSAGE:
- case FWRITEMESSAGE:
- case HREADMESSAGE:
- case HWRITEMESSAGE:
- case GETOBJRECTMESSAGE:
- case SETOBJRECTMESSAGE:
- case SECTOBJRECTMESSAGE:
- case CLICKMESSAGE:
- case KEYMESSAGE:
- case SETSELECTMESSAGE:
- case GETSELECTMESSAGE:
- case COMPAREMESSAGE:
- return(TRectObj(hndl, message, data));
- break;
-
- case GETBBOXMESSAGE:
- TRectObj(hndl, message, data);
- if (mDerefCommon(hndl)->selected) {
- rct = mDerefRRect(hndl)->rect;
- w = mDerefRRect(hndl)->width;
- h = mDerefRRect(hndl)->height;
- grabber.top = rct.top + (h / 2);
- grabber.left = rct.left + (w / 2);
- grabber.bottom = (grabber.top -= 3) + 6;
- grabber.right = (grabber.left -= 3) + 6;
- rptr = (Rect *)data;
- if (rptr->right < grabber.right)
- rptr->right = grabber.right;
- if (rptr->bottom < grabber.bottom)
- rptr->bottom = grabber.bottom;
- }
- break;
-
- case HITTESTMESSAGE:
- click = (ClickInfo *)data;
- hhndl = (TreeObjHndl)TRectObj(hndl, message, data);
- /* We must call TRectObj::HITTESTMESSAGE to set some static
- ** variables that TRectObj::SELECTOBJMESSAGE uses. */
- if ((!hhndl) && (click->message == HITTESTGRABBER)) {
- if (mDerefRoot(GetRootHndl(hndl))->numSelected == 1) {
- if (mDerefRRect(hndl)->selected) {
- rct = mDerefRRect(hndl)->rect;
- where = click->localEvent.where;
- GetMouse(&curMouse);
- grabber.top = pt.v = (rct.top + (mDerefRRect(hndl)->height / 2));
- grabber.left = pt.h = (rct.left + (mDerefRRect(hndl)->width / 2));
- grabber.bottom = (grabber.top -= 3) + 6;
- grabber.right = (grabber.left -= 3) + 6;
- if (PtInRect(where, &grabber)) {
- click->localEvent.where = pt;
- click->offset.h = pt.h - curMouse.h;
- click->offset.v = pt.v - curMouse.v;
- click->oldFlip = 0;
- click->newFlip = 0;
- click->grabber = 7;
- hhndl = hndl;
- }
- }
- }
- }
- return((long)hhndl);
- break;
-
- case GETRGNMESSAGE:
- rgn = NewRgn();
- accumRgn = (RgnHandle)data;
- if (accumRgn)
- if (GetHandleSize((Handle)accumRgn) > 10000)
- return((long)rgn);
- OpenRgn();
- rct = mDerefRRect(hndl)->rect;
- FrameRoundRect(&rct, mDerefRRect(hndl)->width, mDerefRRect(hndl)->height);
- CloseRgn(rgn);
- if (accumRgn)
- UnionRgn(rgn, accumRgn, accumRgn);
- return((long)rgn);
- break;
-
- case DRAWMESSAGE:
- rct = mDerefRRect(hndl)->rect;
- h = mDerefCommon(hndl)->penHeight;
- w = mDerefCommon(hndl)->penWidth;
- PenSize(w, h);
- w = mDerefRRect(hndl)->width;
- h = mDerefRRect(hndl)->height;
- switch (data) {
- case DRAWOBJ:
- if (gQDVersion)
- GetForeColor(&rgb);
- ForeColor(whiteColor);
- if (gQDVersion) {
- rgb2 = mDerefRRect(hndl)->contentColor;
- RGBForeColor(&rgb2);
- }
- PaintRoundRect(&rct, w, h);
- ForeColor(blackColor);
- if (gQDVersion) {
- rgb2 = mDerefRRect(hndl)->borderColor;
- RGBForeColor(&rgb2);
- }
- FrameRoundRect(&rct, w, h);
- if (gQDVersion)
- RGBForeColor(&rgb);
- break;
- case ERASEOBJ:
- EraseRoundRect(&rct, w, h);
- break;
- case DRAWSELECT:
- TRectObj(hndl, message, data);
- if (mDerefCommon(hndl)->selected) {
- grabber.top = rct.top + (h / 2);
- grabber.left = rct.left + (w / 2);
- grabber.bottom = (grabber.top -= 3) + 6;
- grabber.right = (grabber.left -= 3) + 6;
- InvertRect(&grabber);
- }
- break;
- case DRAWGHOST:
- PenMode(patXor);
- FrameRoundRect(&rct, w, h);
- break;
- case DRAWMASK:
- FillRoundRect(&rct, w, h, (ConstPatternParam)&qd.black);
- break;
- }
- PenNormal();
- break;
-
- case PRINTMESSAGE:
- TRRectObj(hndl, DRAWMESSAGE, DRAWOBJ);
- break;
-
- #if VH_VERSION
- case VHMESSAGE:
- cptr = ((VHFormatDataPtr)data)->data;
- ccatchr(cptr, 13, 2);
- ccat (cptr, "$10: TRRectObj:");
- ccatchr(cptr, 13, 1);
- ccat (cptr, " $00: selected = ");
- ccatdec(cptr, mDerefRRect(hndl)->selected);
- ccatchr(cptr, 13, 1);
- rct = mDerefRRect(hndl)->rect;
- ccat (cptr, " $02: rect = ($");
- ccatpadhex(cptr, 0, 4, 4, rct.top);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.left);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.bottom);
- ccat (cptr, ",$");
- ccatpadhex(cptr, 0, 4, 4, rct.right);
- ccat (cptr, ")");
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $0A: width = ");
- ccatdec (cptr, mDerefRRect(hndl)->width);
- ccatchr (cptr, 13, 1);
- ccat (cptr, " $0C: height = ");
- ccatdec (cptr, mDerefRRect(hndl)->height);
- return(true);
- break;
- #endif
-
- case SIZEMESSAGE:
- click = (ClickInfo *)data;
- if (click->grabber != 7)
- return(TRectObj(hndl, message, data));
-
- DoTreeObjMethod(hndl, GETOBJRECTMESSAGE, (long)&rct);
- oldw = mDerefRRect(hndl)->width;
- oldh = mDerefRRect(hndl)->height;
-
- GetMouse(&curMouse);
- curMouse.h += click->offset.h;
- curMouse.v += click->offset.v;
- w = (curMouse.h - rct.left) * 2;
- h = (curMouse.v - rct.top) * 2;
- if (w < 10) w = 10;
- if (h < 10) h = 10;
- if (w > (rct.right - rct.left)) w = rct.right - rct.left;
- if (h > (rct.bottom - rct.top)) h = rct.bottom - rct.top;
-
- OSEventAvail(nullEvent, &option);
- if (option.modifiers & shiftKey) {
- if (w > h) w = h;
- if (h > w) h = w;
- }
- if ((w != oldw) || (h != oldh)) {
- mDerefRRect(hndl)->width = w;
- mDerefRRect(hndl)->height = h;
- return(true);
- }
- return(false);
- break;
-
- default:
- break;
- }
-
- return(noErr);
- }
-
-
-
-